from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from ts.models import Teacher, Student

class StudentSerializer(ModelSerializer):
    # teacher = serializers.StringRelatedField()
    # teacher = serializers.SlugRelatedField(read_only=True,slug_field='name')
    # tea_age = serializers.SerializerMethodField()

    # get_ 开头， 系统会自动调用
    # def get_tea_age(self, obj):
    #     # obj 代表当前 模型类对象
    #     return obj.teacher.age

    class Meta:
        model = Student
        fields = '__all__'


class TeacherSerializer(ModelSerializer):

    class Meta:
        model = Teacher
        fields = '__all__'




